var payMethodArray = getStatusData("/global/payMethod.html");
var paidStatus = getStatusData("/global/paidStatus.html");
var payMethodJson = [];
$.each(payMethodArray,function(index, value){
    var payMethodRow ={}
    payMethodRow.id=index;
    payMethodRow.orName=value;
    payMethodJson.push(payMethodRow);
});

//获取付款申请列表的list
//申请单号、申请状态、供应商名称、申请金额、实付金额、支付方式、申请日期、备注
function getPayApOptions(options){
    var initOptions = {
        idField: 'paidAppNumber',
        sortName: 'paidAppNumber',
        sortOrder: 'asc',
        columns: [[{
            width: 150,
            checkbox: true
        }, {
            title: '付款申请号',
            field: 'paidAppNumber',
            width: 120
        }, {
            field: 'paidStatus',
            title: '申请状态',
            width: 100
        }, {
            field: 'providerName',
            title: '供应商名称',
            width: 120
        }, {
            field: 'appAmount',
            title: '申请金额',
            width: 100,
            align:'right',
            formatter: function (value, rowData, rowIndex) {//格式化该字段内的显示
                return formatNum(value);
            }
        }, {
            field: 'realAmount',
            title: '实付金额',
            width: 100,
            align:'right',
            formatter: function (value, rowData, rowIndex) {//格式化该字段内的显示
                return formatNum(value);
            }
        }, {
            field: 'payMethod',
            title: '支付方式',
            width: 120
        }, {
            field: 'paidStarttime',
            title: '申请日期',
            width: 120
        }, {
            field: 'checkDate',
            title: '审批日期',
            width: 120
        }, {
            field: 'remark',
            title: '备注',
            width: 300
        }]]
    }
    if (options != undefined) {
        $.extend(initOptions, options);
    }
    return initOptions;

}

function calculatePaymentToTop() {
    var subRows = $('#subItem').datagrid('getRows');
    var totalApMoment= 0;

    $.each(subRows, function (index, value) {
        var appBalance = parseFloat(value.appBalance ? value.appBalance : 0);
        totalApMoment = totalApMoment.add(appBalance);
    });
    $('#appAmount').numberbox('setValue',totalApMoment.toFixed(2));
}

//供应商代码 签约人不能为空
function validatePaymentTopSubs(flag) {
    if(flag == undefined){
        var memberRow = $('#memberNo').combogrid('grid').datagrid('getSelected');
    }else{
        var memberRow = $('#memberNo').val();
    }

    if (!(memberRow)) {
        return "供应商代码不能为空";
    }
    return "true";
}

function validatePaymentBottomSubs(data) {
    if (data.length > 0) {
        var str = "";
        $.each(data, function (index, value) {
            var hangNo = index + 1;
            if (!isNumberFun(value.appBalance)||value.appBalance<0) {
                str += "第 " + hangNo + " 行" + "申请金额为非空正数字" + "<br/>";
            }
        });
        if (str === "") {
            str = "true";
        }
        return str;
    } else {
        return "必须包含有效子项";
    }
}

function isNumberFun(val){
    var reg = /^\-?\d+\.?\d*$/;
    return reg.test(val);
}




